package com.payment.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.payment.common.base.AjaxResult;
import com.payment.common.support.Convert;
import com.payment.common.utils.StringUtils;
import com.payment.system.domain.ResourcesData;
import com.payment.system.mapper.ResourcesDataMapper;
import com.payment.system.service.IResourcesDataService;

/**
 * 资源数据 服务层实现
 * 
 * @author payment
 * @date 2019-01-24
 */
@Service
public class ResourcesDataServiceImpl implements IResourcesDataService 
{
	@Autowired
	private ResourcesDataMapper resourcesDataMapper;

	/**
     * 查询资源数据信息
     * 
     * @param id 资源数据ID
     * @return 资源数据信息
     */
    @Override
	public ResourcesData selectResourcesDataById(Integer id)
	{
	    return resourcesDataMapper.selectResourcesDataById(id);
	}
	
	/**
     * 查询资源数据列表
     * 
     * @param resourcesData 资源数据信息
     * @return 资源数据集合
     */
	@Override
	public List<ResourcesData> selectResourcesDataList(ResourcesData resourcesData)
	{
		List<ResourcesData> list=resourcesDataMapper.selectResourcesDataList(resourcesData);
		if(list!=null){
			for(ResourcesData data:list){
				if(!StringUtils.isEmpty(data.getUrl())&&(!data.getUrl().contains("http:"))){
					data.setUrl(data.getUrl());
				}

			}
		}
	    return list;
	}
	
    /**
     * 新增资源数据
     * 
     * @param resourcesData 资源数据信息
     * @return 结果
     */
	@Override
	public int insertResourcesData(ResourcesData resourcesData)
	{
	    return resourcesDataMapper.insertResourcesData(resourcesData);
	}
	
	/**
     * 修改资源数据
     * 
     * @param resourcesData 资源数据信息
     * @return 结果
     */
	@Override
	public int updateResourcesData(ResourcesData resourcesData)
	{
	    return resourcesDataMapper.updateResourcesData(resourcesData);
	}

	/**
     * 删除资源数据对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteResourcesDataByIds(String ids)
	{
		return resourcesDataMapper.deleteResourcesDataByIds(Convert.toStrArray(ids));
	}

	@Override
	public AjaxResult selectResourcesDataByType(String type) {
		/*if(StringUtils.isEmpty(type)){
			return AjaxResult.error(1,"获取资源信息失败：缺失参数");
		}*/
		List<ResourcesData> list=resourcesDataMapper.selectResourcesDataByType(type);

		if(list!=null&&list.size()>0){
			for(ResourcesData data:list){
				if(!data.getUrl().contains("http")){
					data.setUrl(data.getUrl());
				}

			}
		}
		return AjaxResult.successAndData("获取资源信息成功",list);
	}



}
